using cmd;
using UnityEngine;

public abstract class Fish : MonoBehaviour
{
    [Header("鱼的生成范围")]
    [SerializeField] private Collider2D Fishspace;
    protected Bounds bounds;
    [Header("鱼的基础数据")]
    [SerializeField] public string fishName;
    [SerializeField] protected int fishQuality;
    [SerializeField] public float fishBaseWeight;
    [SerializeField] protected float fishVolume;
    [SerializeField] protected float fishMoveSpeed;
    [SerializeField] protected float fishSpawnRangePercent;
    [SerializeField] public float fishUnitValue;

    [Header("组件引用")]
    [SerializeField] protected SpriteRenderer _spriteRenderer;
    protected Camera mainCamera;



    public FishDataDTO _fishData;

    public virtual void Awake()
    {
        if (!_spriteRenderer) _spriteRenderer = GetComponent<SpriteRenderer>();
        mainCamera = Camera.main;

        GameObject Fishsapce_ = GameObject.Find("Fishspace");
        Fishspace = Fishsapce_.GetComponent<BoxCollider2D>();
        Bounds bounds = Fishspace.bounds;
    }

    public virtual void Start()
    {
        InitializeMovement();
        CalculateBounds();
    }

    private void Update()
    {
        Move();
        CheckBounds();
    }

    // 初始化鱼的移动方式（由子类实现）
    protected abstract void InitializeMovement();

    // 鱼的移动逻辑（由子类实现）
    protected abstract void Move();

    // 计算边界（可被子类重写）
    protected virtual void CalculateBounds() { }

    // 边界检测（可被子类重写）
    protected virtual void CheckBounds() { }

    // 调转方向（可被子类重写）
    protected virtual void ReverseDirection() { }


    // 应用数据到鱼（可被子类扩展）
    public virtual void Initialize(FishDataDTO data)
    {
        _fishData = data;
        ApplyDataToFish();
        ApplyFishProperties();
    }

    // 应用DTO数据到鱼对象
    protected virtual void ApplyDataToFish()
    {
        if (_fishData == null) return;

        fishName = _fishData.Name;
        fishQuality = _fishData.Quality;
        fishBaseWeight = _fishData.BaseWeight;
        fishVolume = _fishData.Volume;
        fishMoveSpeed = _fishData.MoveSpeed;
        fishSpawnRangePercent = _fishData.SpawnRangePercent;
        fishUnitValue = _fishData.UnitValue;
    }

    // 根据鱼的数据设置属性
    protected virtual void ApplyFishProperties()
    {

    }


}